package n2591;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	
	static int a[]=new int[10000001];
	
	static int p[]= {0,0};
	
	static void init()
	{
		a[0]=1;
		for(int i=1;i<10000000;i++)
		{
			int min=Math.min(a[p[0]]*2+1, a[p[1]]*3+1);
			if(a[p[0]]*2+1==min)p[0]=p[0]+1;
			if(a[p[1]]*3+1==min)p[1]=p[1]+1;
			a[i]=min;
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args)throws Exception {

		init();
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		String line=null;
		while((line=bf.readLine())!=null)
		{
			int n=Integer.parseInt(line);
			System.out.println(a[n-1]);
		}
	}

}
